﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Tools.INSVideoTool
{
    class LoginClientAlwaysWithTimeOut : ILoginClientStrategy
    {
        private ManualResetEvent _manualResetEvent = new ManualResetEvent(false);
        private TimeSpan _timeOut;
        public LoginClientAlwaysWithTimeOut(int timeOutSeconds = 5)
        {
            _timeOut = TimeSpan.FromSeconds(timeOutSeconds);
        }
        public int LoginClient(VideoClient.ClientSummary videoclient, string userName, string passWord, string url)
        {
            int loginNo = 0;
            new Action(() => { loginNo = videoclient.LoginClient(userName, passWord, url); }).BeginInvoke(delegate { _manualResetEvent.Set(); }, null);
            _manualResetEvent.WaitOne(_timeOut);
            return loginNo;
        }
    }
}
